package edu.msg.jthr.backend.service.beans;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import edu.msg.jthr.backend.model.Candidate;
import edu.msg.jthr.backend.repository.CandidateRepository;
import edu.msg.jthr.backend.repository.RepositoryException;
import edu.msg.jthr.backend.service.CandidateService;
import edu.msg.jthr.backend.service.ServiceException;

@Stateless
public class CandidateBean implements CandidateService {

	// private static final Logger LOG = LoggerFactory
	// .getLogger(CandidateBean.class);

	@EJB
	private CandidateRepository candidateDAO;

	public CandidateBean() {
	}

	@Override
	public void insert(Candidate obj) throws ServiceException {
		try {
			candidateDAO.insert(obj);
			// LOG.info("Insertion succeded");
		} catch (RepositoryException e) {
			// LOG.error("Insertion failed - service", e);
			throw new ServiceException();
		}
	}

	@Override
	public Candidate update(Candidate obj) throws ServiceException {
		try {
			Candidate temp = candidateDAO.update(obj);
			// LOG.info("Update succeded");
			return temp;
		} catch (RepositoryException e) {
			// LOG.error("Update failed - service", e);
			throw new ServiceException("Update failed - service", e);
		}
	}

	@Override
	public void delete(Candidate obj) throws ServiceException {
		try {
			candidateDAO.delete(obj);
			// .info("Delete succeded");
		} catch (RepositoryException e) {
			// LOG.error("Delete failed - service", e);
			throw new ServiceException("Delete failed - service", e);
		}
	}

	@Override
	public List<Candidate> getAll() throws ServiceException {
		try {
			List<Candidate> temp = candidateDAO.getAll();
			// LOG.info("getAll succeded");
			return temp;
		} catch (RepositoryException e) {
			// LOG.error("getAll failed - service", e);
			throw new ServiceException("getAll failed - service", e);
		}
	}

	@Override
	public Candidate getById(Long id) throws ServiceException {
		try {
			Candidate temp = candidateDAO.getById(id);
			// LOG.info("getById succeded");
			return temp;
		} catch (RepositoryException e) {
			// LOG.error("getById failed - service", e);
			throw new ServiceException("getById failed - service", e);
		}
	}

	public String saySomething() {
		return "Ez egy fa !";
	}

}
